package com.muyu.danmo.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.danmo.domain.DanmoPrintingFavorite;
import com.muyu.danmo.domain.DanmoPrintingMessage;
import com.muyu.danmo.service.IDanmoPrintingFavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 印刷出版收藏Controller
 *
 * @author kunzong
 * @date 2024-12-05
 */
@RestController
@RequestMapping("/DanmoPrintingFavorite")
public class DanmoPrintingFavoriteController extends BaseController {
    @Autowired
    private IDanmoPrintingFavoriteService danmoPrintingFavoriteService;

    /**
     * 查询印刷出版收藏列表
     */
//    @RequiresPermissions("system:DanmoPrintingFavorite:list")
    @GetMapping("/list")
    public Result list(DanmoPrintingFavorite danmoPrintingFavorite) {
        PageHelper.startPage(danmoPrintingFavorite.getPageNum(), danmoPrintingFavorite.getPageSize());
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (loginUser == null || loginUser.getUserid() == null) {
            return Result.notLoggedIn("请登录");
        }
        Long userId = loginUser.getUserid();
        List<DanmoPrintingMessage> list = danmoPrintingFavoriteService.selectDanmoPrintingFavoriteList(userId);
        PageInfo<DanmoPrintingMessage> danmoInformationPageInfo = new PageInfo<>(list);
        return Result.success(danmoInformationPageInfo);
    }

    /**
     * 导出印刷出版收藏列表
     */
//    @RequiresPermissions("system:DanmoPrintingFavorite:export")
/*    @Log(title = "印刷出版收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoPrintingFavorite danmoPrintingFavorite) {
        List<DanmoPrintingMessage> list = danmoPrintingFavoriteService.selectDanmoPrintingFavoriteList(danmoPrintingFavorite);
        ExcelUtil<DanmoPrintingMessage> util = new ExcelUtil<DanmoPrintingMessage>(DanmoPrintingMessage.class);
        util.exportExcel(response, list, "印刷出版收藏数据");
    }*/

    /**
     * 获取印刷出版收藏详细信息
     */
//    @RequiresPermissions("system:DanmoPrintingFavorite:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id) {
        return Result.success(danmoPrintingFavoriteService.selectDanmoPrintingFavoriteById(id));
    }

    /**
     * 新增印刷出版收藏
     */
//    @RequiresPermissions("system:DanmoPrintingFavorite:add")
    @Log(title = "印刷出版收藏", businessType = BusinessType.INSERT)
    @GetMapping("add/{id}")
    public Result add(@PathVariable("id") Long id) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (loginUser == null || loginUser.getUserid() == null) {
            return Result.notLoggedIn("请登录");
        }
        Long userId = loginUser.getUserid();
        return danmoPrintingFavoriteService.insertDanmoPrintingFavorite(userId, id);
    }

    /**
     * 修改印刷出版收藏
     */
//    @RequiresPermissions("system:DanmoPrintingFavorite:edit")
    @Log(title = "印刷出版收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoPrintingFavorite danmoPrintingFavorite) {
        return Result.success(danmoPrintingFavoriteService.updateDanmoPrintingFavorite(danmoPrintingFavorite));
    }

    /**
     * 取消印刷出版收藏
     */
//    @RequiresPermissions("system:DanmoPrintingFavorite:remove")
    @Log(title = "印刷出版收藏", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (loginUser == null || loginUser.getUserid() == null) {
            return Result.notLoggedIn("请登录");
        }
        Long userId = loginUser.getUserid();
        return danmoPrintingFavoriteService.deleteDanmoPrintingFavoriteByIds(userId, ids);
    }
}
